﻿using IFileHelper;
using System.Collections.Generic;

namespace xycn.pluginsupport.BaseHelperPlugins
{
    /// <summary>
    /// 封装文件操作接口
    /// </summary>
    public class FileHelper
    {

        /// <summary>
        /// 保存ORM插件对象工厂实例
        /// </summary>
        static Dictionary<string, IPluginFactory.IPluginFactory> FileInterfaces =
            new Dictionary<string, IPluginFactory.IPluginFactory>();

        /// <summary>
        /// 开放类工厂，供controller调用
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static IFileHelper.IFileHelper CreateFileService(string name)
        {
            if (!FileInterfaces.ContainsKey(name))
            {
                return null;
            }

            IFileHelper.IFileHelper ret = null;
            IPluginFactory.IPluginFactory serviceFactory = FileInterfaces[name];
            if (serviceFactory != null)
            {
                ret = (IFileHelper.IFileHelper)serviceFactory.CreatePlugin();
            }

            return ret;
        }

        /// <summary>
        /// 添加ORM插件接口
        /// </summary>
        /// <param name="name"></param>
        /// <param name="dbfactory"></param>
        /// <returns></returns>
        public static void Init(string name, IPluginFactory.IPluginFactory filefactory)
        {
            if (FileInterfaces.ContainsKey(name))
            {
                return ;
            }

            FileInterfaces.Add(name, filefactory);
        }

    }
}
